<?php
session_start();
if (!$_SESSION['logeado'])
    header("Location: login.php");
    
include 'includes/header.php';
include 'includes/classes/task.php';
include 'includes/classes/taskDao.php';
$where = "";
$text = $_REQUEST['text'];
$username= $_REQUEST['username'];
if ($text)
    $where = $where  . " and descripcion like '%$text%'";
if ($username)
    $where = $where  . " and username='$username'";
    
$query = "select * from task where 1 $where order by fecha DESC";
$result = mysql_query($query);

$query_total = "select SEC_TO_TIME(sum(duracion)) as total from task where 1 $where ";
$result_total = mysql_query($query_total);
$row_total = mysql_fetch_array($result_total);
?>
<html>
    <head>
        <script language="javascript" type="text/javascript" src="includes/js/jquery-1.2.6.js"></script>
        <script language="javascript" type="text/javascript" src="includes/js/jquery.form.js"></script>
    </head>
    <body>
    
        
        <table border=1 align="center">
            <tr>
                <td> <b>Username</b></td>
                <td> <b>Descripcion</b></td>
                <td> <b>Fecha</b></td>
                <td> <b>Duracion</b></td>
            </tr>
            <?php while ($result && ($row= mysql_fetch_array($result))){?>
            <tr>
                <td> <?php echo $row['username'];?></td>
                <td> <?php echo $row['descripcion'];?></td>
                <td> <?php echo $row['fecha'];?></td>
                <td> <?php echo $row['duracion'];?></td>
            </tr>
            <?php }?>
            <tr>
                <td colspan="3"> Total</td>
                <td> <?php echo $row_total['total'];?></td>
            </tr>
        </table>
    </body>
</html>
<? include 'includes/footer.php';?>
